package com.bolingcavalry.crm.message.controller;/*
 * @Auther:Sadie
 * @Date:2025/8/1
 * @Description:
 * @VERSON:1.8
 */

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.base.PageResult;
import com.base.ResponseResult;
import com.bolingcavalry.crm.message.service.MessageService;
import com.dto.MessageCreateDTO;
import com.vo.MessageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("消息")
@RestController
@RequestMapping("/message")
@Slf4j
public class MeaasageController {
    @Autowired
    private MessageService messageService;
    @PostMapping("/create")
    public ResponseResult create(MessageCreateDTO dto) {
        log.info("receive message: {}", dto);
        messageService.createMessage(dto);
        return ResponseResult.success("消息创建成功");
    }
    //分页查询分类条件（状态 业务类型）
    @GetMapping("/list")
    @ApiOperation("分页条件查询消息列表")
    public ResponseResult<PageResult<MessageVO>> list(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) String status,         // 消息状态：UNREAD, READ, PROCESSED
            @RequestParam(required = false) String content,         // 消息内容模糊查询
            //增加消息类型 通知类 审核类
            @RequestParam(required = false) String messageType
    ) {

        // 调用服务层分页查询
        IPage<MessageVO> result = messageService.getMessageListByPage(pageNum, pageSize, status, content,messageType);
        PageResult<MessageVO> pageResult = new PageResult<>();
        pageResult.setTotal(result.getTotal());
        pageResult.setPages((int) result.getPages());
        pageResult.setCurrent((int) result.getCurrent());
        pageResult.setSize((int) result.getSize());
        pageResult.setRecords(result.getRecords());
        return ResponseResult.success("查询成功", pageResult);
    }

    //设置状态 同意拒绝(处理消息)
    @PostMapping("/setstatus")
    public ResponseResult setStatus(@RequestBody MessageCreateDTO dto){
        return messageService.updateStatus(dto);
    }

    //查询消息详细内容
    @GetMapping("/get/{id}")
    public ResponseResult<MessageVO> get(@PathVariable Long id){
        return messageService.getMessageById(id);
    }

    //根据对应的售后单号删除对应的消息列表
}
